package com.yanlin.apipassenger.service;

import com.yanlin.apipassenger.remote.ServiceForecastPriceClient;
import com.yanlin.internalcommon.dto.ResponseResult;
import com.yanlin.internalcommon.request.ForecastPriceDTO;
import com.yanlin.internalcommon.response.ForecastPriceResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>标题：ForecastPriceService</p>
 * <p>功能：计价业务</p>
 * <p>
 * 其他说明：
 * </p>
 * <p>审核：</p>
 * <p>重构：</p>
 * <p>创建日期：2025-06-09 15:25</p>
 *
 * @author yanlin
 */
@Service
@Slf4j
public class ForecastPriceService {

    @Autowired
    private ServiceForecastPriceClient serviceForecastPriceClient;
    /**
     * 根据出发地和目的地经纬度，计算预估价格
     * @param depLongitude
     * @param depLatitude
     * @param destLongitude
     * @param destLatitude
     * @return
     */
    public ResponseResult forecastPrice(String depLongitude, String depLatitude, String destLongitude, String destLatitude) {
        log.info("出发地经度={}, 出发地纬度={}, 目的地经度={}, 目的地纬度={}", depLongitude, depLatitude, destLongitude, destLatitude);
        ForecastPriceDTO forecastPriceDTO = new ForecastPriceDTO();
        forecastPriceDTO.setDepLongitude(depLongitude);
        forecastPriceDTO.setDepLatitude(depLatitude);
        forecastPriceDTO.setDestLongitude(destLongitude);
        forecastPriceDTO.setDestLatitude(destLatitude);
        log.info("调用地图服务 计价服务，计算价格");
        ResponseResult<ForecastPriceResponse> result = serviceForecastPriceClient.forecastPrice(forecastPriceDTO);
        double price = result.getData().getPrice();


        ForecastPriceResponse forecastPriceResponse = new ForecastPriceResponse();
        forecastPriceResponse.setPrice(price);
        return ResponseResult.success(forecastPriceResponse);
    }

}